<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
function rq($key=null,$default = null){
    if(!$key) return Requset::all();
    return Request($key,$default);
}
function paginate($page=1,$limit=16){
    $limit = $limit?:16;
    $page = $page?:1;
    $skip = ($page?$page-1:0)*$limit;
    return [$limit,$skip];
}

function err($msg){
    return ['status'=>0,'msg'=>$msg];
}
function suc($msg = null,$data = null){
    return ['status'=>1,'msg'=>$msg,'data'=>$data];
}



function user_ins(){
    return $user = new App\User;
}
function question_ins(){
    return $question = new  App\Question;
}
function answers_ins(){
    return $answers = new App\Answer;
}
function comments_ins(){
    return $comments = new App\Comment;
}

Route::any('api/user/reset',function (){
    return user_ins()->reset_password();
});

Route::any('api/user/exist',function (){
    return user_ins()->exists();
});

Route::any('api/user/validate_reset_password',function (){
    return user_ins()->validate_reset_password();
});


Route::any('api/user/read',function (){
    return user_ins()->read();
});

Route::get('/', function () {
    return view('index');
});

Route::any('api',function (){
    return ['version'=>0.1];
});
Route::any('api/user/signup',function (){

    return user_ins()->signup();
});
Route::any('api/user/change_password',function (){

    return user_ins()->change_password();
});
Route::any('api/user/login',function (){

    return user_ins()->login();
});
Route::any('api/user/logout',function (){

    return user_ins()->logout();
});

function is_logged_in(){
    return session('user_id')?:false;
}

Route::any('api/question/add',function (){
    return question_ins()->add();
});
Route::any('api/question/change',function (){
    return question_ins()->change();
});
Route::any('api/question/read',function (){
    return question_ins()->read();
});
Route::any('api/question/remove',function (){
    return question_ins()->remove();
});

Route::any('api/answers/add',function (){
    return answers_ins()->add();
});

Route::any('api/answers/change',function (){
    return answers_ins()->change();
});

Route::any('api/answers/read',function (){
    return answers_ins()->read();
});

Route::any('api/answers/vote',function (){
    return answers_ins()->vote();
});

Route::any('api/comment/add',function (){
    return comments_ins()->add();
});

Route::any('api/comment/read',function (){
    return comments_ins()->read();
});
//指定模型中的方法
Route::any('api/comment/remove',function (){
    return comments_ins()->remove();
});
//指定控制器的方法
Route::any('api/timeline','CommonController@timeline');

Route::any('tpl/page/home',function (){
    return view("page.home");
});
Route::any('tpl/page/login',function (){
    return view("page.login");
});
Route::any('tpl/page/signup',function (){
    return view("page.signup");
});
Route::any('tpl/page/question_add',function (){
    return view("page.question_add");
});



